/**
 * Copyright (c) 2018-2028, Chill Zhuang 庄骞 (smallchill@163.com).
 * <p>
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * <p>
 * http://www.apache.org/licenses/LICENSE-2.0
 * <p>
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.springblade.oa.wrappper;

import org.springblade.core.tool.api.R;
import org.springblade.oa.entity.Bx;
import org.springblade.core.mp.support.BaseEntityWrapper;
import org.springblade.core.tool.utils.BeanUtil;
import org.springblade.core.tool.utils.SpringUtil;
import org.springblade.oa.mapper.ExpenseAccountMapper;
import org.springblade.oa.service.IBxService;
import org.springblade.oa.service.IExpenseAccountService;
import org.springblade.oa.vo.BxVo;
import org.springblade.system.feign.IDictClient;
import org.springblade.system.feign.ISysClient;
import org.springblade.system.user.entity.UserInfo;
import org.springblade.system.user.feign.IUserClient;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * 包装类,返回视图层所需的字段
 *
 * @author Chill
 */
public class BxWrapper extends BaseEntityWrapper<Bx, BxVo> {

	private static IBxService bxService;

	private static IDictClient dictClient;

	private static IUserClient userClient;

	private static ISysClient sysClient;

	private static IExpenseAccountService expenseAccountService;

	static {
		bxService = SpringUtil.getBean(IBxService.class);
		dictClient = SpringUtil.getBean(IDictClient.class);
		userClient = SpringUtil.getBean(IUserClient.class);
		sysClient = SpringUtil.getBean(ISysClient.class);
		expenseAccountService=SpringUtil.getBean(IExpenseAccountService.class);
	}

	public static BxWrapper build() {
		return new BxWrapper();
	}

	@Override
	public BxVo entityVO(Bx bx) {
		BxVo bxVo = BeanUtil.copy(bx, BxVo.class);
		R<String> ccsyName = dictClient.getValue("cc_sy", bxVo.getXcmd());
		if (ccsyName.isSuccess()) {
			bxVo.setCcsyName(ccsyName.getData());
		}
		R<String> bxlxName = dictClient.getValue("bx_type", bxVo.getBxlx());
		if (bxlxName.isSuccess()) {
			bxVo.setBxlxName(bxlxName.getData());
		}
		R<String> bxdwName = dictClient.getValue("bx_company", bxVo.getBxdw());
		if (bxdwName.isSuccess()) {
			bxVo.setBxdwName(bxdwName.getData());
		}
		/*R<UserInfo> userInfo = userClient.userInfo(Long.valueOf(bx.getCreateUser().longValue()));
		if (userInfo.isSuccess()) {
			bxVo.setBxrName(userInfo.getData().getUser().getRealName());
		}*/
		String userName = expenseAccountService.getUserById(bx.getCreateUser());
		bxVo.setBxrName(userName);

		bxVo.setBmidName(sysClient.getDeptName(bx.getBmid()));
		return bxVo;
	}
}
